package com.asset.config.oss;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableAutoConfiguration
@ConfigurationProperties(prefix = "oss")
public class OssConfig {
    /**
     * logger
     */
    private static final Logger logger = LoggerFactory.getLogger(OssConfig.class);

    private String accessKeyID;

    private String accessKeySecret;

    private String normalEndpoint;

    private String imageEndpoint;

    @Bean(name = "normalOss")
    public OSS buildNormalOssClient(){
        OSS ossClient = new OSSClientBuilder().build(normalEndpoint, accessKeyID, accessKeySecret);
        return ossClient;
    }

    @Bean(name="imageOss")
    public OSS buildInnerOssClient(){
        OSS ossClient = new OSSClientBuilder().build(imageEndpoint, accessKeyID, accessKeySecret);
        return ossClient;
    }

    public static Logger getLogger() {
        return logger;
    }

    public String getAccessKeyID() {
        return accessKeyID;
    }

    public void setAccessKeyID(String accessKeyID) {
        this.accessKeyID = accessKeyID;
    }

    public String getAccessKeySecret() {
        return accessKeySecret;
    }

    public void setAccessKeySecret(String accessKeySecret) {
        this.accessKeySecret = accessKeySecret;
    }

    public String getNormalEndpoint() {
        return normalEndpoint;
    }

    public void setNormalEndpoint(String normalEndpoint) {
        this.normalEndpoint = normalEndpoint;
    }

    public String getImageEndpoint() {
        return imageEndpoint;
    }

    public void setImageEndpoint(String imageEndpoint) {
        this.imageEndpoint = imageEndpoint;
    }
}
